<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
      <el-form-item label="姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="查铺时间" prop="checkDate">
        <el-date-picker clearable
                        v-model="queryParams.checkDate"
                        format="yyyy-MM-dd HH:mm"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm"
                        placeholder="请输入时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="值班干部" prop="cadresOnDuty">
        <el-input
          v-model="queryParams.cadresOnDuty"
          placeholder="请输入值班干部"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="查铺时间" prop="checkTime">
        <el-input
          v-model="queryParams.checkTime"
          placeholder="请输入查铺时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>-->
      <br/>
      <div style="text-align: right;">

        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </div>
        <br/>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dfx:inspection:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:dfx:inspection:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dfx:inspection:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:inspection:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inspectionList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="ID" align="center" prop="id" />-->
      <el-table-column label="姓名" align="center" prop="username" />
<!--      <el-table-column label="身份证号" align="center" prop="idNumber" />-->
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="查铺时间" align="center" prop="checkDate" />
      <el-table-column label="值班干部" align="center" prop="cadresOnDuty" />
<!--      <el-table-column label="查铺时间" align="center" prop="checkTime" />-->
<!--      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">-->
<!--        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">-->
<!--        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope" >
          <el-button
            size="mini"
            type="text"

            @click="handleUpdate(scope.row)"
            v-hasPermi="['dfx:inspection:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handleDelete(scope.row)"
            v-hasPermi="['dfx:inspection:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['dfx:inspection:query']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改查铺记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">查铺记录基本信息
              </p>
            </el-divider>
          </el-header>
          <el-main>
        <el-row>
          <el-col :span="12">
        <el-form-item label="姓名" prop="username">
          <el-input v-model="form.username" placeholder="请输入姓名" />
        </el-form-item>
          </el-col>
          <el-col :span="12">
<!--        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>-->
            <el-form-item label="电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="值班干部" prop="cadresOnDuty">
              <el-input v-model="form.cadresOnDuty" placeholder="请输入值班干部" />
            </el-form-item>
<!--        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>-->
          </el-col>
          <el-col :span="12">
        <el-form-item label="查铺时间" prop="checkDate">
          <el-date-picker clearable
                          v-model="form.checkDate"
                          format="yyyy-MM-dd HH:mm"
                          style="width:100%;"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm"
                          placeholder="请输入查铺时间">
          </el-date-picker>
        </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>
          <el-col :span="12">

          </el-col>
          <el-col :span="12">
&lt;!&ndash;        <el-form-item label="查铺时间" prop="checkTime">
          <el-input v-model="form.checkTime" placeholder="请输入查铺时间" />
        </el-form-item>&ndash;&gt;
          </el-col>
        </el-row>-->
<!--            <el-form-item label="查铺说明">
              <editor v-model="form.checkInstruction" :min-height="150"/>
            </el-form-item>-->
            <el-form-item label="查铺说明" prop="causes">
              <el-input v-model="form.checkInstruction" type="textarea" :rows="6" placeholder="请输入内容"/>
              <!-- <editor v-model="form.causes" :min-height="192" placeholder="请输入事由" />-->
            </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="查铺情况" label-width="20%" prop="gender">
          <el-select v-model="form.checkStatus" placeholder="请选择查铺情况" style="width:90%;float:left">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>-->
<!--        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
        </el-form-item>-->
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

<!--    &lt;!&ndash;详细信息&ndash;&gt;
    <el-dialog :title="view.title" :visible.sync="view.open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">查铺记录基本信息
              </p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名" prop="username">
                  <el-input v-model="form.username" placeholder="请输入姓名" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                &lt;!&ndash;        <el-form-item label="身份证号" prop="idNumber">
                          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
                        </el-form-item>&ndash;&gt;
                <el-form-item label="电话" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入电话" readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="值班干部" prop="cadresOnDuty">
                  <el-input v-model="form.cadresOnDuty" placeholder="请输入值班干部" readonly="true"/>
                </el-form-item>
                &lt;!&ndash;        <el-form-item label="电话" prop="phone">
                          <el-input v-model="form.phone" placeholder="请输入电话" />
                        </el-form-item>&ndash;&gt;
              </el-col>
              <el-col :span="12">
                <el-form-item label="查铺时间" prop="checkDate">
                  <el-date-picker clearable
                                  v-model="form.checkDate"
                                  format="yyyy-MM-dd HH:mm"
                                  readonly="true"
                                  style="width:100%;"
                                  type="datetime"
                                  value-format="yyyy-MM-dd HH:mm"
                                  placeholder="请输入查铺时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            &lt;!&ndash;        <el-row>
                      <el-col :span="12">

                      </el-col>
                      <el-col :span="12">
            &lt;!&ndash;        <el-form-item label="查铺时间" prop="checkTime">
                      <el-input v-model="form.checkTime" placeholder="请输入查铺时间" />
                    </el-form-item>&ndash;&gt;
                      </el-col>
                    </el-row>&ndash;&gt;
            <el-form-item label="查铺说明" prop="causes">
              <el-input v-model="form.checkInstruction" type="textarea" :rows="6" placeholder="请输入内容"/>
              &lt;!&ndash; <editor v-model="form.causes" :min-height="192" placeholder="请输入事由" />&ndash;&gt;
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" readonly="true"/>
            </el-form-item>
            &lt;!&ndash;        <el-form-item label="查铺情况" label-width="20%" prop="gender">
                      <el-select v-model="form.checkStatus" placeholder="请选择查铺情况" style="width:90%;float:left">
                        <el-option
                          v-for="dict in dict.type.sys_user_sex"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>&ndash;&gt;
            &lt;!&ndash;        <el-form-item label="备注1" prop="note1">
                      <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注2" prop="note2">
                      <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注3" prop="note3">
                      <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注4" prop="note4">
                      <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注5" prop="note5">
                      <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注6" prop="note6">
                      <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注7" prop="note7">
                      <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注8" prop="note8">
                      <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注9" prop="note9">
                      <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="备注10" prop="note10">
                      <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
                    </el-form-item>&ndash;&gt;
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewCancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listInspection, getInspection, delInspection, addInspection, updateInspection } from "@/api/module/dfx/inspection";

export default {
  name: "Inspection",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查铺记录表格数据
      inspectionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: null,
        idNumber: null,
        phone: null,
        checkDate: null,
        cadresOnDuty: null,
        checkTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 用户查询参数
      view:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询查铺记录列表 */
    getList() {
      this.loading = true;
      listInspection(this.queryParams).then(response => {
        this.inspectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    viewCancel() {
      this.view.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        username: null,
        idNumber: null,
        phone: null,
        checkDate: null,
        cadresOnDuty: null,
        checkTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 详细按钮操作 */
    handleView(row) {
     /* const id = row.id || this.ids
      getInspection(id).then(response => {
        this.form = response.data;
        this.view.open = true;
        this.view.title = "值班记录信息查看";

      });*/
      const id = row.id;
      this.$router.push({ path:"/zonghe/inspection_detail", query: {id}});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加查铺记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInspection(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改查铺记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInspection(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInspection(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除查铺记录编号为"' + ids + '"的数据项？').then(function() {
        return delInspection(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/inspection/export', {
        ...this.queryParams
      }, `inspection_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
